//
//  AStarTool.swift
//  A-star
//
//  Created by xukai on 2018/1/10.
//  Copyright © 2018年 xukai. All rights reserved.
//  算法类抽取

import UIKit

class AStarTool: NSObject {
    
    // 计算两点间的距离
    class func getDistance(p1 : CGPoint, p2 : CGPoint) -> Int
    {
        // 对角算法
        let cnX = Int(abs(p1.x - p2.x))
        let cnY = Int(abs(p1.y - p2.y))
        if cnX > cnY
        {
            return 14 * cnY + 10 * (cnX - cnY)
        }
        else
        {
            return 14 * cnX + 10 * (cnY - cnX)
        }
    }
    
    // 返回周围的点坐标
    class func getNeibourhood(p : CGPoint, max : Int) -> Array<CGPoint>
    {
        var list = [CGPoint]()
        for i in -1...1
        {
            for j in -1...1
            {
                // 跳过自己
                if i == 0 && j == 0
                {
                    continue
                }
                
                // 边界
                let x = i + Int(p.x)
                let y = j + Int(p.y)
                if x < 0 || x >= max || y < 0 || y >= max
                {
                    continue
                }
                
                let tmP = CGPoint(x: x, y: y)
                list.append(tmP)
            }
        }
        
        return list
    }
    
    
    
    
    

}
